<?php
/**
 *（Logic）(Amazon物流动作/操作)
 */
namespace App\Logic\Amazon\Api;

use App\Models\Basics\AmazonAccount;
use App\Models\CustomerDelivery\CustomerDelivery;
use App\Models\CustomerDelivery\CustomerDeliveryDetail;

class CustomerOutBoundWork
{
    /**
     * 单个,同步amazon物流单号
     * @param $accountId
     * @param $seller_fulfillment_order_id
     * @throws \Exception
     */
    public static function grabByCon($accountId,$seller_fulfillment_order_id): void
    {
        $count = CustomerDeliveryDetail::query()
            ->where('delivery_type',1) //Amazon-FBA发货方式
            ->where('sync_status', 0) //Amazon物流信息未同步
            ->where('account_id', $accountId)
            ->where('delivery_order_no', $seller_fulfillment_order_id)
            ->where('created_at', '>=', '2024-11-01 00:00:00')
            ->count();
        if($count > 0){
            $account = AmazonAccount::query()->find($accountId);
            $requiredConfig = RequiredConfig::getInit();
            $config = $requiredConfig->configuration($account->refresh_token, $account->aws_region);
            CustomerOutbound::apiGetFulfillmentOrder($config,$account,$seller_fulfillment_order_id);
        }
    }

}
